//
// Created by 11510 on 2024/6/22.
//
template<class T>
class RAII {
public:
    RAII(T *data) : _data(data) {}

    ~RAII() {
        if (_data) {
            delete _data;
            _data = nullptr;
        }
    }

    T *operator->();

    T &operator*();

    T *get() const {
        return _data;
    }

    void set(T *data);

    RAII(const RAII &) = delete;

    RAII &operator=(const RAII &) = delete;

private:
    T *_data;
};

template<class T>
T *RAII<T>::operator->() {
    return _data;
}

template<class T>
T &RAII<T>::operator*() {
    return *_data;
}

template<class T>
void RAII<T>::set(T *data) {
    if (_data) {
        delete _data;
        _data = nullptr;
    }
    _data = data;
}





